筆記目錄

Skip to content

在 Windows 上安裝與升級 PowerShell 7

我原本看到 Windows PowerShell 啟動時出現的提示:「安裝最新的 PowerShell 以取得新功能和改進功能!」,以為只是沒更新到最新版本,直到點進去才發現 5 以前和 6 以後其實是不同產品,然後 Windows 提示安裝最新的 PowerShell 頁面上有這麼一段話:

我需要安裝 PowerShell 7 嗎? 不,除非你對 PowerShell 7 有特定功能需求,否則不需要安裝它。

既然官方明確說沒有特別需求不需要安裝,便沒有理會。沒想到後來 Copilot CLI 的腳本工具要求 PowerShell v6 或更新版本,對 Windows PowerShell 5.1 僅提供實驗性支援且有版本檢查阻擋,只好回頭安裝,順便寫一篇說明方便日後維護。

Windows PowerShell 與 PowerShell 7 的差異

Windows PowerShell 與 PowerShell 7 是完全不同的產品線(目前最新版本分別為 5.1 與 7.6,其中 7.6 為 LTS 版本),詳細說明可參考 PowerShell 官方文件

  • 底層架構:Windows PowerShell 基於封閉的 .NET Framework,僅限 Windows 系統;PowerShell 7 基於開源的 .NET(目前 7.6 是使用 .NET 10),可跨平台運行於 Windows、Linux 與 macOS 甚至 Docker 容器中。
  • 生命週期與定位:Windows PowerShell 已停止新功能開發,僅維護性更新,不再加入新功能。
  • 預設編碼與亂碼問題:PowerShell 7 統一採用 UTF-8(不含 BOM)作為所有輸出的預設編碼,解決了 Windows PowerShell 時代處理純文字檔、中文字元或與 Git 互動時經常發生的亂碼問題。
  • 執行檔隔離:兩者可以完全並存於同一台電腦中互不干擾。Windows PowerShell 的執行檔名為 powershell.exe,而 PowerShell 7 為了區別,更名為 pwsh.exe

安裝指南

WinGet 安裝後會自動設定環境變數(pwsh.exe 加入 PATH),無需手動配置。

搜尋可用版本:

powershell
winget search --id Microsoft.PowerShell

安裝最新穩定版 (如 7.6):

powershell
winget install --id Microsoft.PowerShell --source winget

一鍵升級至最新版:

powershell
winget upgrade --id Microsoft.PowerShell

解除安裝:

powershell
winget uninstall --id Microsoft.PowerShell

Get-Help 說明文件機制

安裝 PowerShell 只是安裝「執行引擎」,詳細的離線說明文件(包含範例、參數解說)預設不會一併打包,需要另外下載。若想用 -Examples 查看範例、或用 -Detailed 查看完整參數說明,卻沒有輸出,可能就是說明檔尚未下載。

若需要完整範例說明,有兩種方式:

  • 連線查詢:在指令後加上 -Online 參數(例如 Get-Help Get-Process -Online),直接開啟瀏覽器查看官方網頁版說明,不佔本機空間。

  • 下載離線檔:以系統管理員身分執行以下指令,將說明檔下載至本機:

    powershell
    Update-Help -UICulture zh-tw, en-US -Force -ErrorAction SilentlyContinue

各參數說明:

  • -UICulture zh-tw, en-US:指定下載語言。加上 en-US 作為備援,因部分模組沒有繁體中文版說明。
  • -Force:即使本機說明檔已是最新版,仍強制重新下載。
  • -ErrorAction SilentlyContinue:忽略失敗的錯誤輸出。部分模組未提供線上說明檔,若不加此參數,終端機會出現大量紅色錯誤訊息,但不影響其他模組的下載。

完整的 Updatable Help 機制說明可參考 about_Updatable_Help

Get-Help 的所有參數說明可參考 Get-Help

說明文件下載前後的差異範例

以下為執行 Get-Help Get-Process 在下載說明文件前後的輸出對比。

下載前,僅有基本語法,且末尾提示說明文件不存在:

text
NAME
    Get-Process

SYNTAX
    Get-Process [[-Name] <string[]>] [-Module] [-FileVersionInfo] [<CommonParameters>]

    Get-Process [[-Name] <string[]>] -IncludeUserName [<CommonParameters>]

    Get-Process -Id <int[]> [-Module] [-FileVersionInfo] [<CommonParameters>]

    Get-Process -Id <int[]> -IncludeUserName [<CommonParameters>]

    Get-Process -InputObject <Process[]> [-Module] [-FileVersionInfo] [<CommonParameters>]

    Get-Process -InputObject <Process[]> -IncludeUserName [<CommonParameters>]


ALIASES
    gps
    ps


REMARKS
    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
        -- To download and install Help files for the module that includes this cmdlet, use Update-Help.
        -- To view the Help topic for this cmdlet online, type: "Get-Help Get-Process -Online" or
           go to https://go.microsoft.com/fwlink/?LinkID=2096814.

下載後,包含完整的描述、語法與相關連結:

text
NAME
    Get-Process

SYNOPSIS
    Gets the processes that are running on the local computer.


SYNTAX
    Get-Process [-FileVersionInfo <System.Management.Automation.SwitchParameter>] [-Module <System.Management.Automatio
    n.SwitchParameter>] [[-Name] <System.String[]>] [<CommonParameters>]

    Get-Process -IncludeUserName <System.Management.Automation.SwitchParameter> [[-Name] <System.String[]>] [<CommonPar
    ameters>]

    Get-Process [-FileVersionInfo <System.Management.Automation.SwitchParameter>] -Id <System.Int32[]> [-Module <System
    .Management.Automation.SwitchParameter>] [<CommonParameters>]

    Get-Process -Id <System.Int32[]> -IncludeUserName <System.Management.Automation.SwitchParameter> [<CommonParameters
    >]

    Get-Process [-FileVersionInfo <System.Management.Automation.SwitchParameter>] -InputObject <System.Diagnostics.Proc
    ess[]> [-Module <System.Management.Automation.SwitchParameter>] [<CommonParameters>]

    Get-Process -IncludeUserName <System.Management.Automation.SwitchParameter> -InputObject <System.Diagnostics.Proces
    s[]> [<CommonParameters>]


DESCRIPTION
    The `Get-Process` cmdlet gets the processes on a local computer.

    Without parameters, this cmdlet gets all processes on the local computer. You can also specify a specific process b
    y process name or process ID (PID), or by piping a **System.Diagnostics.Process** object to this cmdlet.

    By default, this cmdlet returns a **Process** object that has detailed information about the process and supports m
    ethods that let you control it. With parameters, you can change the type of information returned by this cmdlet.

    - **Module**: Retrieve information for each module loaded into the process. - **FileVersionInfo**: Retrieve file ve
    rsion information for the main module of the process.

    > [!NOTE] > A module is an executable file or a dynamic link library (DLL) loaded into a process. A process > has o
    ne or more modules. The main module is the module used to initially start the process. For > more information, see
    [ProcessModule Class](/dotnet/api/system.diagnostics.processmodule).


RELATED LINKS
    Online Version https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-process?view=power
    shell-7.5&WT.mc_id=ps-gethelp
    Debug-Process Debug-Process.md
    Get-Process Get-Process.md
    Start-Process Start-Process.md
    Stop-Process Stop-Process.md
    Wait-Process Wait-Process.md
    Where-Object ../Microsoft.PowerShell.Core/Where-Object.md

REMARKS
    To see the examples, type: "Get-Help Get-Process -Examples"
    For more information, type: "Get-Help Get-Process -Detailed"
    For technical information, type: "Get-Help Get-Process -Full"
    For online help, type: "Get-Help Get-Process -Online"

什麼情況下需要額外安裝新版?

目前的經驗,以下幾個讓我覺得值得安裝新版:

  • AI 腳本基準:AI 幫忙產生的腳本,常常是以 PowerShell 6+ 為基準,所以常常會先執行失敗,問它原因才發現是版本問題。
  • 編碼問題:目前主流工具寫入檔案時,UTF-8 編碼預設都是無 BOM,若腳本中有中文字,Windows PowerShell 5.1 執行時會把腳本當 ANSI 解析,導致字串誤判、亂碼或執行失敗。
  • 工具有最低版本要求:Copilot CLI 等工具明確要求 PowerShell 6+,對 5.1 僅提供實驗性支援。
  • 跨平台腳本需求:若希望建立可在 Windows、Linux、macOS 上通用的工具腳本,PowerShell 6+ 是必要條件。

兩者可以並存,不需移除 Windows PowerShell。

異動歷程

  • 2026-03-25 初版文件建立。